package au.edu.utas.yu_qiao_group.luckyman.ui.components;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;

import androidx.appcompat.widget.SearchView;
import androidx.cursoradapter.widget.CursorAdapter;
import au.edu.utas.yu_qiao_group.luckyman.R;

public class ArrayAdapterSearchView extends SearchView {

  private SearchView.SearchAutoComplete mSearchAutoComplete;

  public ArrayAdapterSearchView(Context context) {
    super(context);
    initialize(context);
  }

  public ArrayAdapterSearchView(Context context, AttributeSet attrs) {
    super(context, attrs);
    initialize(context);
  }

  public void initialize(Context context) {
    mSearchAutoComplete = (SearchView.SearchAutoComplete) findViewById(R.id.search_src_text);
    mSearchAutoComplete.setDropDownBackgroundDrawable(new ColorDrawable(context.getColor(R.color.colorPrimaryDark)));
    this.setAdapter(null);
    this.setOnItemClickListener(null);
  }

  @Override
  public void setSuggestionsAdapter(CursorAdapter adapter) {
    // don't let anyone touch this
  }

  public void setOnItemClickListener(AdapterView.OnItemClickListener listener) {
    mSearchAutoComplete.setOnItemClickListener(listener);
  }

  public void setAdapter(ArrayAdapter<?> adapter) {
    mSearchAutoComplete.setAdapter(adapter);
  }

  public void setText(String text) {
    mSearchAutoComplete.setText(text);
  }
}
